﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AssetManagementSystem.Model {
    public class Hold {

        string studentId;
        string assetId;
        DateTime dateCreated;

        public Hold(string studentId, string assetId)
            : this(studentId, assetId, DateTime.Now) {
            //Creates a new hold
        }

        public Hold(string studentId, string assetId, DateTime dateCreated) {
            this.studentId = studentId;
            this.assetId = assetId;
            this.dateCreated = dateCreated;
        }

        public string StudentId {
            get { return this.studentId; }
            set { this.studentId = value; }
        }

        public string AssetId {
            get { return this.assetId; }
            set { this.assetId = value; }
        }

        public DateTime DateCreated {
            get { return this.dateCreated; }
            set { this.dateCreated = value; }
        }

        public bool IsAvailable {
            get {
                LoanManager tmpMan = new LoanManager();
                return tmpMan.isLoanAssetAvailable(this.assetId);
            }
        }

        public DateTime DueBack {
            get {
                LoanManager tmpMan = new LoanManager();
                foreach (Loan loan in tmpMan.GetAllLoans()) {
                    if (loan.Assets.ContainsKey(assetId) && loan.Assets[assetId] == DateTime.MinValue)
                        return loan.DueDate;
                }

                //default return.
                return DateTime.MinValue;
            }
        }

        public override string ToString() {
            return studentId + ", " + assetId + ", " + dateCreated.ToString(); 
        }
    }
}
